'use strict';
const db = uniCloud.database()
const coll = db.collection('user')
const coll1 = db.collection('userform')
exports.main = async (event, context) => {
	console.log(event)
	//查询openid是否在userform提交过表单
	let res1 = await coll1.where({
		openid:event.openid
	}).get()
	console.log(res1)
	if (res1.data.length>0) {
		return {success:false,msg:'用户已提交过报名表单！'}
	} else{
		let res2 = await coll.where({
			openid:event.openid
		}).get()
		let res3 = await coll1.add(Object.assign(res2.data[0],event))
		return {success:true,msg:'提交报名成功！'}
	}
	
	
};
